﻿package com.core
{
    import flash.utils.*;

    dynamic public class Obproxy extends Proxy
    {
        private var changed:Boolean = false;
        private var obs:Array;
        protected var _item:Object = null;
        private var _name:String = "";
        protected var _action:Object = "";
        protected var _state:Object = "";

        public function Obproxy(param1:Object = null, param2:String = null)
        {
            this.obs = new Array();
            if (param1 == null)
            {
                param1 = new Object();
            }
            this.setItem(param1);
            this.setName(param2);
            return;
        }// end function

        public function setItem(param1:Object) : void
        {
            this._item = param1;
            if (param1.hasOwnProperty("state"))
            {
                this._state = param1.state;
            }
            else if (param1.hasOwnProperty("action"))
            {
                this._action = param1.action;
            }
            return;
        }// end function

        public function getName() : String
        {
            return this._name;
        }// end function

        public function setName(param1:String) : void
        {
            this._name = param1;
            return;
        }// end function

        public function get action() : Object
        {
            return this._action;
        }// end function

        public function set action(param1:Object) : void
        {
            var _loc_2:* = this._action;
            this._action = param1;
            this.setChanged();
            var _loc_3:* = ProxyChange.getInstance("action", _loc_2, param1);
            this.notifyObservers(_loc_3);
            _loc_3.destory();
            return;
        }// end function

        public function get state() : Object
        {
            return this._state;
        }// end function

        public function set state(param1:Object) : void
        {
            var _loc_2:* = this._state;
            this._state = param1;
            this.setChanged();
            var _loc_3:* = ProxyChange.getInstance("state", _loc_2, param1);
            this.notifyObservers(_loc_3);
            _loc_3.destory();
            return;
        }// end function

        public function addObserver(param1:Obinder) : void
        {
            if (param1 == null)
            {
                throw new Error();
            }
            if (this.obs.indexOf(param1) == -1)
            {
                this.obs.push(param1);
            }
            return;
        }// end function

        public function deleteObserver(param1:Obinder) : void
        {
            var _loc_2:* = this.obs.indexOf(param1);
            if (_loc_2 > -1)
            {
                this.obs.splice(_loc_2, 1);
            }
            return;
        }// end function

        public function notifyObservers(param1:Object = null) : void
        {
            var _loc_2:Array = null;
            if (!this.changed)
            {
                return;
            }
            _loc_2 = this.obs.slice();
            this.clearChanged();
            var _loc_3:* = _loc_2.length - 1;
            while (_loc_3 >= 0)
            {
                
                _loc_2[_loc_3].update(this, param1);
                _loc_3 = _loc_3 - 1;
            }
            return;
        }// end function

        public function deleteObservers() : void
        {
            this.obs.splice(0, this.obs.length);
            return;
        }// end function

        protected function setChanged() : void
        {
            this.changed = true;
            return;
        }// end function

        protected function clearChanged() : void
        {
            this.changed = false;
            return;
        }// end function

        public function hasChanged() : Boolean
        {
            return this.changed;
        }// end function

        public function countObservers() : int
        {
            return this.obs.length;
        }// end function

        override function setProperty(param1, param2) : void
        {
            var _loc_3:* = this._item[param1];
            if (_loc_3 !== param2)
            {
                this._item[param1] = param2;
            }
            this.setChanged();
            var _loc_4:* = ProxyChange.getInstance(param1, _loc_3, param2);
            this.notifyObservers(_loc_4);
            _loc_4.destory();
            return;
        }// end function

        override function getProperty(param1)
        {
            return this._item[param1];
        }// end function

    }
}
